package com.model.auto.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.model.auto.Major;
import com.model.auto.MajorV2;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

/**
 * 专业学校信息
 * @author zhaoyifan
 * @date 2023/9/2 22:16
 */
@Data
public class MajorSchoolInfo {
    /**
     * 类型1:理工2:文史
     */
    private Integer type;
    /**
     * 学校code
     */
    private String schoolCode;
    /**
     * 学校名称
     */
    private String schoolName;
    /**
     * 专业组code
     */
    private String groupCode;

    /**
     * 专业code
     */
    private String majorName;

    /**
     * 专业level
     */
    private String level;

    /**
     * 专业code
     */
    private String majorCode;

    /**
     * 批次
     */
    private String batch;

    /**
     * 录取人数
     */
    private int enterCount;

    /**
     * 最高分/平均/最低分
     */
    private String score;

    /**
     * 位次
     */
    private String weici;

    private String subject;

    private String recruitType;


    public static MajorSchoolInfo toMajorSchoolInfo(Major major){
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");

        MajorSchoolInfo majorSchoolInfo = new MajorSchoolInfo();
        majorSchoolInfo.setType(major.getType());
        majorSchoolInfo.setSchoolCode(major.getSchoolCode());
        majorSchoolInfo.setSchoolName(major.getSchoolName());
        majorSchoolInfo.setMajorCode(major.getMajorCode());
        majorSchoolInfo.setMajorName(major.getMajorName());
        majorSchoolInfo.setBatch(major.getBatch());
        if(StringUtils.hasText(major.getMsg2017())){
            List<String> msg = Arrays.asList(major.getMsg2017().split("\\|"));
            if(msg.size() >= 3){
                String enterCount = msg.get(0).split("/")[0];
                if(msg.get(0).split("/").length == 2){
                    enterCount = msg.get(0).split("/")[1];
                }
                if(StringUtils.hasText(enterCount) && pattern.matcher(enterCount).matches()){
                    majorSchoolInfo.setEnterCount(Integer.valueOf(enterCount));
                }else{
                    majorSchoolInfo.setEnterCount(0);
                }
                majorSchoolInfo.setScore(msg.get(1));
                majorSchoolInfo.setWeici(msg.get(2));
            }
        }
        return majorSchoolInfo;
    }

    public static MajorSchoolInfo toMajorSchoolInfo(MajorV2 major){
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");

        MajorSchoolInfo majorSchoolInfo = new MajorSchoolInfo();
        majorSchoolInfo.setType(major.getType());
        majorSchoolInfo.setSchoolCode(major.getSchoolCode());
        majorSchoolInfo.setSchoolName(major.getSchoolName());
        majorSchoolInfo.setMajorCode(major.getMajorCode());
        majorSchoolInfo.setMajorName(major.getMajorName());
        majorSchoolInfo.setLevel(major.getLevel());
        majorSchoolInfo.setGroupCode(major.getGroupCode());
        majorSchoolInfo.setSubject(major.getSubject());
        majorSchoolInfo.setRecruitType(major.getRecruitType());
        majorSchoolInfo.setBatch(major.getBatch());
        if(StringUtils.hasText(major.getMsg2017()) && !"暂无数据".equals(major.getMsg2017())){
            List<String> msg = Arrays.asList(major.getMsg2017().split("\\|"));
            if(msg.size() >= 3){
                String enterCount = msg.get(0).split("/")[0];
                if(msg.get(0).split("/").length == 2){
                    enterCount = msg.get(0).split("/")[1];
                }
                if(StringUtils.hasText(enterCount) && pattern.matcher(enterCount).matches()){
                    majorSchoolInfo.setEnterCount(Integer.valueOf(enterCount));
                }else{
                    majorSchoolInfo.setEnterCount(0);
                }
                majorSchoolInfo.setScore(msg.get(1));
                majorSchoolInfo.setWeici(msg.get(2));
            }
        } else if (StringUtils.hasText(major.getMsg2016())) {
            List<String> msg = Arrays.asList(major.getMsg2016().split("\\|"));
            if (msg.size() >= 3) {
                String enterCount = msg.get(0).split("/")[0];
                if (msg.get(0).split("/").length == 2) {
                    enterCount = msg.get(0).split("/")[1];
                }
                if (StringUtils.hasText(enterCount) && pattern.matcher(enterCount).matches()) {
                    majorSchoolInfo.setEnterCount(Integer.valueOf(enterCount));
                } else {
                    majorSchoolInfo.setEnterCount(0);
                }
                majorSchoolInfo.setScore(msg.get(1));
                majorSchoolInfo.setWeici(msg.get(2));
            }
        }
        return majorSchoolInfo;
    }
}
